<%@page import="com.dxl.dao.common.context.SessionContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@ include file="/WEB-INF/view/common/loginCheck.jspf" %>
<div class="easyui-panel" data-options="fit:true,footer:'#productCateEditBtns'" style="padding:10px;">
    <form id="productCateEditForm" method="post">
		 <table style="width:100%">
             <tr>
                 <td>名称:</td>
                 <td>
                	<input type="hidden" name="id" value="${entity.id}" />
                	
                	<input type="hidden" id="path" name="path" value="${entity.path}" />
                	<img id="pathImg" width="100px" height="100px" src="<%=SysPropCacheManager.getPropValue("oss.imageAccessUrl")%>/${entity.path}" />
					<input type="file" id="pathFileField" />
					<div id="pathFileFieldQueueID"></div>
					
                 	<input class="easyui-textbox" style="width:200px;" type="text" name="name" value="${entity.name}" data-options="required:true" />
                 </td>
             </tr>
             
             <tr>
                 <td>父品类:</td>
                 <td>
                 	<input id="parentProductCate" type="hidden" name="pid" value="${entity.pid}" />
                	<input id="productCateSelectTree" type="text" style="width:180px;">
	                <a href="javascript:void(0)" title="清空品类" class="easyui-linkbutton" onclick="clearParentProductCate();" data-options="iconCls:'icon-no'"></a>
                 </td>
             </tr>
             
             <tr>
                 <td>描述:</td>
                 <td>
                 	<input class="easyui-textbox" style="width:250px;" type="text" name="description" value="${entity.description}" />
                 </td>
             </tr>
             <tr>
                 <td>状态:</td>
                 <td>
                 	<select name="state">
                 		<option value="1" <c:if test="${entity.state == 1}">selected="selected"</c:if>>启用</option>
                 		<option value="0" <c:if test="${entity.state == 0}">selected="selected"</c:if>>草稿</option>
                 		<option value="-1" <c:if test="${entity.state == -1}">selected="selected"</c:if>>停用</option>
                 		<option value="-2" <c:if test="${entity.state == -2}">selected="selected"</c:if>>删除</option>
                 	</select>
                 </td>
             </tr>
         </table>
	</form>
</div>
<t:permission codes="PRODUCTCATE-VIEW,PRODUCTCATE-MODIFY">
<div id="productCateEditBtns" style="text-align:right;padding:2px;">
	<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveArea();">保存</a>
</div>
</t:permission>

<script type="text/javascript">
	$(function () {
		$('#productCateEditForm').form({
		    url:'${ROOT}/productCate/save?_rt=' + new Date().getTime(),
		    ajax: true,
		    onSubmit: function() {
		    	return $(this).form('enableValidation').form('validate');
		    },
		    success:function(data) {
		    	var json = eval('(' + data + ')');
				if (json.success) {
					APP.message('保存成功');
		        	$('#productCateEditDlg').dialog('close');
		        	$('#productCateDataList').treegrid('reload');
					$('#productCateDataList').treegrid('clearSelections');
		        	$('#productCateDataList').treegrid('clearChecked');
		        } else {
		        	 APP.error(json.msg);
		        }
		    }
		});
		
		APP.initUpload({
			id: '#pathFileField',
			url: '${ROOT}/ossupload?logined-session-id=<%=SessionContext.getSessionId()%>&size=<%=SysPropCacheManager.getPropValue("product.image.size")%>',
			fileTypeExts: '*.jpg;*.jpge;*.png',
			auto: true,
			multi: false,
			queueID: 'pathFileFieldQueueID',
			callback: function (data) {
				if (data.success) {
					$('#pathImg').attr('src', '<%=SysPropCacheManager.getPropValue("oss.imageAccessUrl")%>/' + data.data);
					$('#path').val(data.data);
				}
			}
		});
		
		$('#productCateSelectTree').combotree({
		    url: '${ROOT}/productCate/tree?_rt=' + new Date().getTime(),
		    onSelect: function (node) {
		    	$('#parentProductCate').val(node.id);
		    },
		    onLoadSuccess: function (node, data) {
		    	$('#productCateSelectTree').combotree('setValue', '${entity.pid}');
		    }
		});
	});
	
	function saveArea() {
		$('#productCateEditForm').submit();
	}
	
	function clearParentProductCate() {
		$('#productCateSelectTree').combotree('clear');
		$('#parentProductCate').val('');
	}
	
	function closeAreaEditDlg() {
		$('#productCateEditDlg').dialog('close');
	}
</script>